package org.codert.web;

import lombok.Data;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.util.NoSuchElementException;

/**
 * @description:
 * @author: TanJingyu
 * @create: 2021-06-04 15:48
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping(value = "{id}")
    public String test(@PathVariable String id) {
        if ("1".equals(id)) {
            throw new NoSuchElementException("异常。。。。");
        }
        return id;
    }

    @PostMapping("/val")
    public String valid(@RequestBody InnerValid innerValid) {
        return innerValid.getEmail();
    }

    @Data
    public static class InnerValid {
        @NotNull
        private Integer id;
        @Email
        private String email;
    }
}
